package com.ruoyi.zxjd.conference.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.zxjd.conference.domain.ConferenceArrange;
import com.ruoyi.zxjd.conference.service.IConferenceArrangeService;
import com.ruoyi.zxjd.work.domain.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zxjd.conference.domain.ConferenceProgress;
import com.ruoyi.zxjd.conference.service.IConferenceProgressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 填报进度Controller
 * 
 * @author lcc
 * @date 2021-02-07
 */
@Controller
@RequestMapping("/conference/progress")
public class ConferenceProgressController extends BaseController
{
    private String prefix = "conference/progress";

    @Autowired
    private IConferenceProgressService conferenceProgressService;

    @Autowired
    private IConferenceArrangeService conferenceArrangeService;

    @RequiresPermissions("conference:progress:view")
    @GetMapping()
    public String progress()
    {
        return prefix + "/progress";
    }

    /**
     * 查询填报进度列表
     */
    @RequiresPermissions("conference:progress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ConferenceProgress conferenceProgress)
    {
        startPage();
        List<ConferenceProgress> list = conferenceProgressService.selectConferenceProgressList(conferenceProgress);
        return getDataTable(list);
    }

    /**
     * 导出填报进度列表
     */
    @RequiresPermissions("conference:progress:export")
    @Log(title = "填报进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ConferenceProgress conferenceProgress)
    {
        List<ConferenceProgress> list = conferenceProgressService.selectConferenceProgressList(conferenceProgress);
        ExcelUtil<ConferenceProgress> util = new ExcelUtil<ConferenceProgress>(ConferenceProgress.class);
        return util.exportExcel(list, "progress");
    }

    /**
     * 新增填报进度
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        ConferenceArrange conferenceArrange = new ConferenceArrange();
        conferenceArrange.setStatus("1");
        List<ConferenceArrange> conferenceArranges = conferenceArrangeService.selectConferenceArrangeList(conferenceArrange);
        mmap.put("conferenceArranges",conferenceArranges);
        mmap.put("today",DateUtils.getDate());
        return prefix + "/add";
    }

    /**
     * 新增保存填报进度
     */
    @RequiresPermissions("conference:progress:add")
    @Log(title = "填报进度", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ConferenceProgress conferenceProgress)
    {
        int j = conferenceProgressService.insertConferenceProgress(conferenceProgress);
        int count=0;
        if (j==3){
            count=1;
        }else {
            count=0;
        }
        return toAjax(count);
    }

    /**
     * 修改填报进度
     */
    @GetMapping("/edit/{progressId}")
    public String edit(@PathVariable("progressId") Long progressId, ModelMap mmap)
    {
        ConferenceProgress conferenceProgress = conferenceProgressService.selectConferenceProgressById(progressId);
        mmap.put("conferenceProgress", conferenceProgress);
        return prefix + "/edit";
    }

    /**
     * 修改保存填报进度
     */
    @RequiresPermissions("conference:progress:edit")
    @Log(title = "填报进度", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ConferenceProgress conferenceProgress)
    {
        return toAjax(conferenceProgressService.updateConferenceProgress(conferenceProgress));
    }

    /**
     * 删除填报进度
     */
    @RequiresPermissions("conference:progress:remove")
    @Log(title = "填报进度", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(conferenceProgressService.deleteConferenceProgressByIds(ids));
    }

    /**
     * 跳转会议填报页面
     */
    //@RequiresPermissions("work:progress:fill")
    @GetMapping("/fill_in/{progressId}")
    public String fullIn(@PathVariable("progressId") Long progressId, ModelMap mmap)
    {
        ConferenceProgress conferenceProgress = conferenceProgressService.selectConferenceProgressById(progressId);
        //ConferenceArrange conferenceArrange = conferenceArrangeService.selectConferenceArrangeById(conferenceProgress.getArrangeId());
        mmap.put("conferenceProgress", conferenceProgress);
        //mmap.put("conferenceArrange", conferenceArrange);
        mmap.put("today", DateUtils.getDate());
        return prefix + "/fill_in";
    }

}
